﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace ChessGameEngine
{
    public class ChessBoard 
    {
        private readonly TileState[,] boardState;

        public ChessBoard(TileState[,] boardState)
        {
            this.boardState = boardState;
        }

        public IEnumerable<Piece> GetReachablePiecesFor(TilePosition position, PieceColor color)
        {
/*
            var list = GetPiecesOnBoard(color);
            foreach (var piece in list)
            {
                if (piece.GetAllPossibleMoves().Where(p => p == position).Any())
                    yield return piece;
            }
*/
            return new List<Piece>();
        }

        public IEnumerable<Piece> GetPiecesOnBoard(PieceColor color)
        {
            for (int i = 0; i < ChessEngine.MaxTiles; i++)
            {
                for (int j = 0; j < ChessEngine.MaxTiles; j++)
                {
                    var piece = boardState[i, j].Piece;
                    if (piece != null && piece.Color == color)
                        yield return piece;
                }                
            }
        }
    }
}
